<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="app"></div>
    <div id="app1"></div>
    <script src="../js/babel.min.js"></script>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script type="text/babel">
      class Count extends React.Component {
        state = { count: 0 };
        add = () => {
          const { count } = this.state;
          this.setState({ count: count + 1 }, () => {
            console.log("更新完成后调用 >>> ", this.state.count);
          });
          console.log("count :>> ", this.state.count);
        };
        reduce = () => {
          // this.setState((state, props) => {
          //   console.log("state :>> ", state);
          //   console.log("props :>> ", props);
          // });
          this.setState((state) => ({ count: state.count - 1 }));
        };
        render() {
          return (
            <div>
              <h3>count = {this.state.count}</h3>
              <br />
              <button onClick={this.add}>+1</button>
              <button onClick={this.reduce}>-1</button>
            </div>
          );
        }
      }
      ReactDOM.render(<Count />, document.getElementById("app1"));
    </script>
  </body>
</html>
